package com.web.java0328springboot.controller;


import com.web.java0328springboot.entity.ResponseResult;
import com.web.java0328springboot.util.OssUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class UploadController {

    /**
     * 文件上传
     * MultipartFile 用户上传的文件
     */
    @RequestMapping("/upload")
    public ResponseResult upload(MultipartFile file) throws IOException {
        //OSS上传
        OssUtils.upload(file.getInputStream(),file.getOriginalFilename());
        //获得url
        String url = OssUtils.getURL(file.getOriginalFilename());
        return new ResponseResult(200,"OK",url);
    }
}
